﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UI.Desktop
{
    static internal class CommonControls
    {
        public enum FormMode { New, Modify };

        static public void ClearControls(ref Panel panel)
        {
            foreach (Control c in panel.Controls)
            {
                Type t = c.GetType();

                if (t == typeof(TextBox))
                {
                    TextBox txt = c as TextBox;
                    c.Text = "";
                }
                else if (t == typeof(ComboBox))
                {
                    ComboBox cmb = c as ComboBox;
                    cmb.SelectedIndex = -1;
                }
                else if (t == typeof(DateTimePicker))
                {
                    DateTimePicker dtp = c as DateTimePicker;
                    dtp.Value = DateTime.Today;
                }
            }
        }

        static public void ErrorBox(string caption, string message)
        {
            MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        static public DialogResult AskBox(string caption, string question)
        {
            return MessageBox.Show(question, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        }

        static public DialogResult WarnBox(string caption, string question)
        {
            return MessageBox.Show(question, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
        }

        static public void InformBox(string caption, string message)
        {
            MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        static public void CarrerasToCombo(ref ComboBox cmb)
        {
            cmb.DataSource = new Logic.Carreras().GetCollection();
            cmb.DisplayMember = "Nombre";
            cmb.ValueMember = "ID";
        }

        static public void PlanesToCombo(ref ComboBox cmb, Entities.Carrera carrera)
        {
            cmb.DataSource = new Logic.Planes().GetByCarrera(carrera);
            cmb.DisplayMember = "Nombre";
            cmb.ValueMember = "ID";
        }

        static public void NumberTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!((e.KeyChar == (char)Keys.Enter) || char.IsDigit(e.KeyChar) || (e.KeyChar == (char)Keys.Back))) e.Handled = true;
        }
    }
}
